<?php 
class ProfilensModel extends CI_Model {
    
    function ProfilensModel()
    {
        // Call the Model constructor
       // parent::Model();
    }
    function getinfosens($id)
    {
		$this->db->select('nom, prenom, email, ville, login, password');
		$this->db->from('user');
		$query = $this->db->get();
		return $query->result();
    }
    
    function setNom()
    {       
                $this->nom   = $this->session->userdata('nom');
                $this->prenom   = $this->session->userdata('prenom');
                $this->ville   = $this->session->userdata('ville');
    }
    
   function ajouter($data) {
    
		$this->db->insert('user', $data);

    }
    /*
     
    function getListeFomation($returnData = false)
    {
         $this->db->select('idformation, nom');
         $this->db->from('formation');       
        $this->listeFormation =  $this->db->get();
        if ($returnData)
        {
            return array(
                'listeFormation' => $this->listeFormation 
            );
        }
    }
    
    */
 /*  function EnregistreFormInscription()
    {        
        $sql = "INSERT INTO user(nom,prenom,login,password,ville,email,typeuser,formation_idformation,enAttenteValidation) values('".$_POST['Nom']."','".$_POST['Prenom']."','".$_POST['Email']."','".$this->chaine_aleatoire(8)."','".$_POST['Ville']."','".$_POST['Email']."',".$_POST['ckTypeInscription'].",".$_POST['ListeFormationInscription'].",1) ";
        $this->db->query($sql);         
    }
  */  
    
    // Génération d'une chaine aléatoire
    function chaine_aleatoire($nb_car, $chaine = 'azertyuiopqsdfghjklmwxcvbn123456789')
    {
        $nb_lettres = strlen($chaine) - 1;
        $generation = '';
        for($i=0; $i < $nb_car; $i++)
        {
            $pos = mt_rand(0, $nb_lettres);
            $car = $chaine[$pos];
            $generation .= $car;
        }
        return $generation;
    }
}
